<link rel="stylesheet" type="text/css" href="/css/admingoods/publish.css?v=0.0.0" media="all" />		
<script type="text/javascript" src="/js/admingoods/publish.js?v=0.0.0" ></script>
<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=10ci2Syk2wU83q4CA6KzmOxw5LW32xHO"></script>
<script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=10ci2Syk2wU83q4CA6KzmOxw5LW32xHO"></script>
<script type="text/javascript" charset="utf-8" src="/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<div class="pt15 pl15">当前位置：<span class="layui-breadcrumb"><a href="/">首页</a><a href="/admingoods/default/index">商品管理</a><a><cite>添加商品</cite></a></span></div>
<div class="layui-fluid publish-outter">
    <div class="layui-card p30">		
		<div class="border-b pb15 f22">添加商品</div>
		<div class="layui-card-body pt30 pb15">	
			<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
			  <ul class="layui-tab-title">
			    <li class="layui-this">基本信息</li>
				<?php if($first_cate == 1){ ?>
			    <li>地图标注</li>
				<?php }?>
			    <li>详细介绍</li>
			  </ul>
			  <div class="layui-tab-content">
			    <div class="layui-tab-item layui-show">
					<div class="layui-row">
							<div class="layui-col-xs12 layui-col-md8">					
							    <div class="layui-form-item">
									<label class="layui-form-label"><span class="must-input">*</span>选择分类：</label>
									<div class="layui-input-block">
										<input type="hidden" name="first_cate" id="first_cate" value="<?= $first_cate?>"/>
										<select name="second_cate" id="second_cate">
										    <option value="0">请选择分类</option>
										    <?php foreach($category as $cate){ ?>
										    <option value="<?=$cate['id']?>"><?=$cate['name']?></option>
										    <?php } ?>
										</select>
										<select name="third_cate" id="third_cate"><option value="0">请选择分类</option></select>
									</div>
							    </div>  
								<div class="layui-form-item">
									<label class="layui-form-label"><span class="must-input">*</span>商品名称：</label>
									<div class="layui-input-block">
										<input type="text" data-must="1" id="goodsname" name="goodsname" required  lay-verify="required" placeholder="请输入商品名称" class="layui-input"/>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label"><span class="must-input">*</span>商品价格：</label>
									<div class="layui-input-inline">
										<input type="text" data-must="1" id="price" name="price" required  lay-verify="required" placeholder="请输入商品价格"  class="layui-input"/>
									</div>
									<div class="layui-form-mid layui-word-aux"><span id="goodsprice_format">元/<?= $first_cate==1?"月":"件" ?></span></div>
								</div> 
								<?php if($first_cate == 1){ ?>
								<div class="layui-form-item" id="install-price-line">
								<div class="layui-form-label"><span class="must-input">*</span>安装维护费：</div>
								    <div class="layui-input-inline"><input type="text" data-must="1" id="install_price" name="install_price" class="layui-input"/></div>
									<div class="layui-form-mid layui-word-aux">元/月</div>
								</div>
								<div class="layui-form-item" id="areanum-line">
								    <div class="layui-form-label"><span class="must-input">*</span>面积：</div>
									<div class="layui-input-inline"><input type="text" data-must="1" id="area_num" name="area_num" class="layui-input"/></div>
								</div>
								<div class="layui-form-item" id="order-endtime-line">
								    <div class="layui-form-label"><span class="must-input">*</span>起售时间：</div>
									<div class="layui-input-inline"><input type="text" data-must="1" name="order_endtime" id="order_endtime" class="layui-input"/></div>
								</div>
								<?php }?>
								
								<div class="layui-form-item" id="package-line">
								    <div class="layui-form-label"><span class="must-input">*</span>是否多套餐：</div>
									<div class="layui-input-inline"><select name="have_package" data-must="1" id="have_package"><option value="0">否</option><option value="1">是</option></select></div>
								</div>
								<div  class="publish-package-item-line" id="package-area-outter">
								    <div class="layui-form-label">&nbsp;</div>
								    <div class="layui-input-inline">
								        <div id="package-area-container">
								            <textarea name="package" id="package" class="package-input-textarea" placeholder=""></textarea>
								            <div id="package-description" class="package-description"></div>
								        </div>
								    </div>
								</div>
								
								<div id="attr-area-outter"></div>
								<div class="publish-img-line">
								    <div class="layui-form-label"><span class="must-input">*</span>商品图片：</div>
								    <div class="layui-input-block">
								        <blockquote class="layui-elem-quote layui-quote-nm">
								            <div class="uploadimg-display-outter" id="uploadimg-display-outter">
								                <div class="filebutton">
								                    <div class="content"><div><i class="layui-icon">&#xe624;</i><p>添加图片</p></div></div>
								                    <input type="file" style="cursor: pointer;" id="goodsimg-upload" multiple="multiple" name="goodsimg[]" accept="image/*"/>
								                </div>
								            </div>
								        </blockquote>
								    </div>
								</div>
							</div>				
						</div>       
					
				</div>					
				<?php if($first_cate == 1){ ?>
			    <div class="layui-tab-item">
					<div id="location-line">
						<input type="hidden" id="longitude" name="longitude" value="" placeholder="经度">
						<input type="hidden" placeholder="经度" value="" id="latitude" name="latitude">
						<input type="hidden" value="" id="region_area" name="region_area">
						<input type="hidden" value="" id="address" name="address">
						<div id="allmap"></div>
					</div>
				</div>					
				<?php }?>
			    <div class="layui-tab-item">
					<script id="introduction" type="text/plain" name="gdesc"></script>					
				</div>
			  </div>
			</div>
			
		</div>		
		<div class="pt30 border-t text-c"> 
			<button type="submit" class="layui-btn layui-btn-normal" id="publish-submit-button">提交</button>
			<a class="layui-btn layui-btn-primary" href="/admingoods/default/index">取消</a>					
		</div>		
    </div>
</div>
<script type="text/javascript">
	$(document).ready(function(){
	
	layui.use('laydate', function(){
	  var laydate = layui.laydate;  
	  //执行一个laydate实例
	  laydate.render({
		elem: '#order_endtime' //指定元素
	  });
	});

	var map = new BMap.Map("allmap");          // 创建地图实例
	var initLat = 39.916527;
	var initLng = 116.397128;
	var point = new BMap.Point(initLng, initLat);  // 创建点坐标  
	map.centerAndZoom(point, 15);  
	// var marker = new BMap.Marker(point);        // 创建标注    
	// map.addOverlay(marker);                     // 将标注添加到地图中			
	map.enableScrollWheelZoom();                   // 启用滚轮放大缩小 
	//获取当前位置
	var geolocation = new BMap.Geolocation();  
	geolocation.getCurrentPosition(function(r){  
		if(this.getStatus() == BMAP_STATUS_SUCCESS){  
			mk = new BMap.Marker(r.point);  
			mk.addEventListener("dragend", showInfo);
			mk.enableDragging();    //可拖拽		                
			getAddress(r.point);
			map.addOverlay(mk);//把点添加到地图上  
			map.panTo(r.point);
			window.parent.$('#longitude').val(r.point.lng);
			window.parent.$('#latitude').val(r.point.lat);
		}else {  
			alert('failed'+this.getStatus());  
		}  
	});
	
	//绑定Marker的拖拽事件
	function showInfo(e){
		var gc = new BMap.Geocoder();
		gc.getLocation(e.point, function(rs){
			console.log(rs)
			var addComp = rs.addressComponents;
			//var address = addComp.province +  addComp.city + addComp.district + addComp.street + addComp.streetNumber;//获取地址
                        var region_area = addComp.province +' '+  addComp.city +' '+  addComp.district;//获取地址
                        var address = addComp.street +' '+ addComp.streetNumber;//获取地址
                        console.log(region_area);	
                        console.log(address);		
			//画图 ---》显示地址信息
			var label = new BMap.Label(address,{offset:new BMap.Size(20,-10)});
			map.removeOverlay(mk.getLabel());//删除之前的label 	
			mk.setLabel(label);
			window.parent.$('#longitude').val(e.point.lng);
			window.parent.$('#latitude').val(e.point.lat);
			window.parent.$('#region_area').val(region_area);
			window.parent.$('#address').val(address);								
		});
	}		        
	//获取地址信息，设置地址label
	function getAddress(point){
		var gc = new BMap.Geocoder();		            
		gc.getLocation(point, function(rs){
			var addComp = rs.addressComponents;
			var address =  addComp.province +  addComp.city + addComp.district + addComp.street + addComp.streetNumber;//获取地址
			//画图 ---》显示地址信息
			var label = new BMap.Label(address,{offset:new BMap.Size(20,-10)});
			map.removeOverlay(mk.getLabel());//删除之前的label 
			mk.setLabel(label);				
		});		 
	}
	});
</script>